/**
 * 考勤管理-异常记录
 */
import React from 'react';
import { connect } from 'umi';
import { Row, Input } from 'antd';
import PageRouter from '@/components/PageRouter/PageRouter';
import moment from 'moment';
import { CompanyDepartPlus } from '@/containers';
import DateRange from '@/components/DateRange';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import AuthCode from '@/utils/auth/AuthCode';

import { withRoutePage } from '@/utils/enhanceUtils';
import MissList from './MissList';
import LateList from './LateList';
import AbsenceList from './AbsenceList';

class AbnormalRank extends React.Component {
    constructor(props) {
        super(props);
        this.authCode = new AuthCode(props.route.code).authCode;
    }

    render() {
        const { route, location } = this.props;
        const { pathname, query } = location;
        const { startTime, endTime, employeeName: userName, quarter, dateType } = query;

        const config = [
            {
                field: 'companyDepart',
                label: '机构',
                component: <CompanyDepartPlus />
            },
            {
                field: 'userName',
                label: '员工',
                config: {
                    initialValue: userName || ''
                },
                component: <Input placeholder="输入姓名" />
            },
            {
                field: 'date',
                config: {
                    initialValue: {
                        range: [
                            !startTime ? moment().startOf('month') : moment(startTime),
                            !endTime ? moment() : moment(endTime)
                        ],
                        quarter: quarter ? Number(quarter) : 1,
                        type: !dateType ? 'month' : dateType
                    }
                },
                component: (
                    <DateRange
                        range
                        dateTypes={[
                            {
                                label: '本周',
                                type: 'week'
                            },
                            {
                                label: '本月',
                                type: 'month'
                            },
                            {
                                label: '本年',
                                type: 'year'
                            }
                        ]}
                    />
                )
            }
        ];

        const renderPage = () => {
            const componentProps = { route, location, config, authCode: this.authCode('export') };
            const pageMap = {
                '/office/personnelManagement/attendance/timetag/abnormalRank': <MissList {...componentProps} />,
                '/office/personnelManagement/attendance/timetag/abnormalRank/latelist': (
                    <LateList {...componentProps} />
                ),
                '/office/personnelManagement/attendance/timetag/abnormalRank/absencelist': (
                    <AbsenceList {...componentProps} />
                )
            };
            return pageMap[pathname] || null;
        };

        return (
            <PageHeaderWrapper>
                <PageRouter type="abnormalRank">
                    <Row>{renderPage()}</Row>
                </PageRouter>
            </PageHeaderWrapper>
        );
    }
}
export default withRoutePage(
    connect(({ abnormalRank }) => ({
        abnormalRank
    }))(AbnormalRank)
);
